<?php
/*
 * Created on Feb 23, 2010
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
	include('includes/session.php');
	$title = TT_HOME;		
	include('header.inc');
	include('lefter.inc');
	echo '<script type="text/javascript" src="js/previewpopup.js"></script>';
	
	echo '<link href="css/popup/default.css" type="text/css" rel="stylesheet">'; 
	echo '<link href="css/popup/alphacube.css" type="text/css" rel="stylesheet">'; 
	
	echo '<script type="text/javascript" src="js/windowjs/effects.js"></script>';
	echo '<script type="text/javascript" src="js/windowjs/window.js"></script>';
	echo '<script type="text/javascript" src="js/windowjs/window_effects.js"></script>';
	echo '<script type="text/javascript" src="js/windowjs/debug.js"></script>';
	
	echo '<div id="col3">';
		echo '<div id="col3_content" class="clearfix"><a id="content" name="content"></a>';
	        echo '<div class="subcolumns_oldgecko widget_space">';
			
				// begin navigation content
				echo '<div class="widget_background">';
					echo '<h3 class="widget_header" style="font-size:14px;">Những bất động sản mới đăng:</h3>';							
				echo '</div>';
				// end navigation content
				
				// begin content
				$result = $transactionModel->getCountItemOfTransaction();				
				echo '<div class="widget_margins">';
					// begin sumary
					echo '<div id="tp_li_topcontent">';							
					echo '<ul class="li_nav floatbox">';
						$i = 0;
						$clsName = '';
						while ($myrow = $transactionModel->getArrayNameTrans($result)){
							switch ($i) {
								case 0: $clsName = 'icon-experts'; break;
								case 1: $clsName = 'icon-companys'; break;
								case 2: $clsName = 'icon-publications'; break;
								case 3: $clsName = 'icon-events'; break;
								default: break;
							}
							echo '<li style="width:auto;" ><a href="#"><span style="font-size: 14px;" class='. $clsName .'>'. $myrow['name'] .' ('. $myrow['itemno'] .')</span></a></li>';
							$i++;
							if ($i > 3) $i = 1;
						}													
					echo '</ul>';
					echo '</div>';
					// end sumary
					
					// begin thong tin nha dat moi nhat
					$start=$_GET['start'];
					if(strlen($start) > 0 and !is_numeric($start)){
						echo "Data Error";
						exit;
					}
					$eu = ($start - 0);
					$limit = MAX_RECORD_INDEX;
					$this1 = $eu + $limit;
					$back = $eu - $limit;
					$next = $eu + $limit;					
					$num = $reesNewModel->getCountItems();
					$result = $reesNewModel->getTopItems($eu, $limit);
							
					echo '<div class="li_background li_height_big">';
						echo '<div id="li_experts" class="li_content">';
							echo '<div class="clear"></div>';
							echo '<div class="floatbox">';
								echo '<div id="topExperts">';						
								
								echo '<ul class="li_elements search">';
									// thong tin nha dat
									$i = 0;
									while ($myrow = $reesNewModel->getArrayNameItem($result)) { 							
										echo '<li class="li_experts vcard" id="id65633">';
											echo '<h3 class="fn url" ><a href="itemrestatedetail.php?itemid='.$myrow['id'].'&type=transaction&transactionId='.$myrow['rees_transaction_id'].'" class="org url person" style="font-size: 14px;">&nbsp;&nbsp;'. $myrow['title'];
											if ($i < 5 && ($eu == 0))
												echo '<img src="images/hot.gif" width="28" height="16" border="0"/></a>';
											else echo '</a>';
											echo '</h3>';
											$imgPath = PATH_ITEM_IMAGE.$myrow['image'];
											if (isset($myrow['image']) && !empty($myrow['image']) && file_exists($imgPath)) {												
												echo '<a href="#" title="Image House" ><img id="house'. $myrow['id'] .'" src="'. $imgPath .'" class="photosearch" alt=""/></a>';												
											} else {
												$imgPath = "img/NoPhotoAvailable.jpg";
												echo '<a href="#" title="No Image" ><img id="house'. $myrow['id'] .'" src="img/NoPhotoAvailable.jpg" class="photosearch" alt=""/></a>';
											}
											echo '<script type="text/javascript">';
												echo 'Event.observe( window, \'load\', function() {';
													echo 'repositionPreviewFor($( \'house'. $myrow['id'] .'\' ));';
													echo '$( \'house'. $myrow['id'] .'\' ).observe( \'mouseover\', showPreview );';
													echo '$( \'house'. $myrow['id'] .'\' ).observe( \'mouseout\', hidePreview );';
												echo '});';
											echo '</script>';
											
											echo '<p class="li_experts_content">';
												echo '<span class="tags">'. $myrow['description'] .'<br/></span>';															
												echo '<br/>';
												echo '<span class="profile">';
												if (!empty($myrow['city_name'])) {
													echo $myrow['city_name'];
													if (!empty($myrow['district_name']))
														echo ' >> '.$myrow['district_name'];													
												}
												if (!empty($myrow['place']))
														echo ' >> '.$myrow['place'];
												echo '</span>';												
											echo '</p>';
											echo '<div class="li_experts_tb">';
												echo '<div class="icon-li-publications" title="Publications"  style="font-size: 12px;">Lượt xem: '. $myrow['showNo'] . ' - <img src="images/calendar-icon.png" />&nbsp;Ngày đăng: '. ConvertSQLDate($myrow['updateDate']) .' - Ngày hết hạn: '. ConvertSQLDate($myrow['endDate']) .'</div>';															
											echo '</div>';												
										echo '</li>';
										$i++;
									}									
									// thong tin nha dat
								echo '</ul>';
								$reesNewModel->dataSeekResult($result, 0);
								while ($myrow = $reesNewModel->getArrayNameItem($result)){	
									$imgPath = PATH_ITEM_IMAGE.$myrow['image'];
									echo '<div id="house'. $myrow['id'] .'_preview" style="display: none" class="preview">';
										echo '<h3>'. $myrow['title'] .'</h3>';
										$widthheight = '';
										if (isset($myrow['image']) && !empty($myrow['image']) && file_exists($imgPath)){
											$imgPath = PATH_ITEM_IMAGE.$myrow['image'];
										}
										else {
											$imgPath = "img/NoPhotoAvailable.jpg";
											$widthheight = ' width="250" height="270"';
										}
										echo '<img src="'. $imgPath .'" alt="'. $myrow['title'] . '" '. $widthheight .'/>';										
									echo '</div>';
								}
								if ($num > $limit ){
									echo '<div id="pager"><span style="font-size: 12px; face=Verdana">Trang </span>';
									if ($back >=0) {  
										echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.$back.'"><img src="img/icons/arrow_left.gif" width="16" height="16" /></a>';
									}
									$i = 0;
									$l = 1;
									for ($i = 0; $i < $num; $i = $i + $limit) {
										if ($i <> $eu) {
											echo " <a href='".$_SERVER['PHP_SELF']."?start=$i'><span style='font-size: 12px; face=Verdana'>$l</span></a> ";
										}
										else { 											
											echo '<span style="font-size: 18px; color: red; face=Verdana">'.$l.'</span>';													
										}
											$l=$l+1;
									}
									if ($this1 < $num) {
										echo '<a href="'.$_SERVER['PHP_SELF'].'?start='.$next.'"><img src="img/icons/arrow_right.gif" width="16" height="16" /></a>';
									}
									echo '<span style="font-size: 12px; face=Verdana"> Tổng cộng '. $num .' bất động sản</span>';
									echo '</div>';
								} else {
									echo '<div id="pager">';
									echo '<span style="font-size: 12px; face=Verdana"> Tổng cộng '. $num .' bất động sản</span>';
									echo '</div>';
								}
								echo '<br/>';
								
								// Transactions restate
								$trans = $transactionModel->getTrans(null, null);
								while ($row = $transactionModel->getArrayNameTrans($trans)) {
									$items = $itemModel->getItemByTransactionId($row['id'], 0, 8);
									$num = $itemModel->countItemByTransactionId($row['id']);
									if ($num <= 0) { continue; }
									echo '<table>
											<thead style="">
												<th style="width: 375px; background-color: #004B80; font-size: 12px;">'.$row['name'].'</th>
												<th style="width: 42px; background-color: #004B80; font-size: 12px;">Ảnh</th>
												<th style="width: 70px; background-color: #004B80; font-size: 12px;">Vị trí</th>
												<th style="width: 75px; background-color: #004B80; font-size: 12px;">Diện tích</th>
												<th style="background-color: #004B80; font-size: 12px;">Giá</th>
												<th style="width: 69px; background-color: #004B80; font-size: 12px;">Ngày đăng</th>
											</thead>';
											$i = 0;
											while ($item = $itemModel->getArrayNameInfos($items)) {
												$altrow = "";
												if ($i % 2) {
													$altrow = 'style="background-color: #FFFFE1"';
												}
												echo '<tr '.$altrow.' class="cityRegion">';
													echo '<td>';
														echo '<a href="itemrestatedetail.php?itemid='.$item['id'].'&type=transaction&transactionId='.$row['id'].'">'.$item['title'].'</a>';
														if ($item['isSpecial'] == 1) {
															echo '<img src="images/hot.gif" width="28" height="16" border="0"/>';
														}
											 		echo '</td>';
											 		echo '<td>';
											 			$fileName = 'img/upload/item/'.$item["image"]; 
											 			echo '<a onclick = "openDialogAdd(\'popup'.$item['id'].'\');" href="javascript:void(0);">';
											 		 		echo '<img src="images/home-icon.png" width="16" height="16" border="0" />';
											 		 	echo '</a>';  
												 		echo '<div id="popup'.$item['id'].'" style="display:none;">';
												 			echo '<h3>'.truncate($item['title'], 50).'</h3>';
															if ($item['image'] && file_exists($fileName)) {
																echo '<img class="photo" alt="" src="'.$fileName.'" width="300px" height="345px" />';
															} else {
																echo '<img class="photo" alt="" src="img/NoPhotoAvailable.jpg" width="300px" height="345px" />';
															}
												 		echo '</div>';		
											 		 echo '</td>';
											 		 echo '<td>'.$item['place'].'</td>';
											 		 echo '<td>'.$item['size'].'</td>';
											 		 echo '<td>'.$item["price"].'</td>';
											 		 echo '<td>'.ConvertSQLDate($item["createDate"]).'</td>';
												 echo '</tr>';
											 	 $i++;
											} // End child while loop
									echo '</table>';
									echo '<br/>';
								} // End while loop
								echo '</div>';
							echo '</div>';
						echo '</div>';
					echo '</div>';
					// end thong tin nha dat moi nhat
					
									
				echo '</div>';// end content
				
				// begin last new

					include('_lastnew.php');
					
				// end last new	
				
			echo '</div>';
		echo '</div>';
	echo '</div>';
								
	include('footer.inc');
?>
<script type="text/javascript">
function openDialogAdd (divid ) {  
	Dialog.alert($ (divid).innerHTML, { className: "alphacube", width: 340, height: 420, okLabel: "Đóng" });
}
</script>
